﻿Imports System.Resources
Imports System.Reflection
Imports System.Globalization

Imports BUS
Imports DTO

Public Class frmLogin

#Region "Xử dụng đa ngôn ngữ "
    Private ReadOnly culInfoMgr As CommonLibrary

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        culInfoMgr = New CommonLibrary() ' '' dung cac bien của lớp
        AddHandler culInfoMgr.OnCultureInfoChanges, AddressOf CultureInfoHasChange

        culInfoMgr.ChangeCultureInfo("vi-VN")

    End Sub

    Private Sub CultureInfoHasChange(ByVal sender As Object, ByVal e As EventArgs)
        Try
            SetUI()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub SetUI()
        Dim culInfo As CultureInfo = culInfoMgr.getCultureinfo()
        Dim str As String
        str = GetType(frmLogin).Assembly.ToString()
        Dim rm As New ResourceManager("Gui.frmLogin", Assembly.GetExecutingAssembly())
        Me.Text = rm.GetString("frmLoginText", culInfo)

        btnThoat.Text = rm.GetString("btnThoatText", culInfo)
        btnLogin.Text = rm.GetString("btnLoginText", culInfo)
        lblChangeLanguage.Text = rm.GetString("lblChangeLanguageText", culInfo)
        lblTieuDe.Text = rm.GetString("lblTieuDeText", culInfo)
        lblUserName.Text = rm.GetString("lblUserNameText", culInfo)
        lblPassWord.Text = rm.GetString("lblPassWordText", culInfo)
        cmbChangeLanguage.Items.Clear()  ''''' cmbLanguage
        cmbChangeLanguage.Items.Add(rm.GetString("cmbChangeLanguagevi_VNText", culInfo))
        cmbChangeLanguage.Items.Add(rm.GetString("cmbChangeLanguageen_USText", culInfo))

        If culInfo.Name = "vi-VN" Then
            cmbChangeLanguage.SelectedIndex = 0
        ElseIf culInfo.Name = "en-US" Then
            cmbChangeLanguage.SelectedIndex = 1
            lblTieuDe.TextAlignment = StringAlignment.Center
        End If
    End Sub



    Private Sub cmbChangeLanguage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbChangeLanguage.SelectedIndexChanged
        If cmbChangeLanguage.SelectedIndex = 0 Then
            culInfoMgr.ChangeCultureInfo("vi-VN")
            NgonNgu.ngon = 0
        ElseIf cmbChangeLanguage.SelectedIndex = 1 Then
            culInfoMgr.ChangeCultureInfo("en-US")
            NgonNgu.ngon = 1
        End If
    End Sub

#End Region


    '    Dim login As Boolean

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Dim str As DialogResult
        If cmbChangeLanguage.SelectedIndex = 0 Then
            str = MessageBox.Show(" Bạn muốn thoát chương trình ?", "Thoát Chương Trình ", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If str = vbYes Then
                Me.Close()
            End If
        Else
            str = MessageBox.Show("Are you Exit Programming?", "Exit Programming", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If str = vbYes Then
                Me.Close()
            End If
        End If

    End Sub

    Public loai As Integer
    Public strHienThi As String


    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        Try

            Dim nvdn As New NhanVienDTO
            nvdn.laytenDN = txtUserName.Text
            nvdn.LayPass = txtPassWord.Text
            strHienThi = txtUserName.Text
            Dim nhanvien As New DangNhapBUS
            If nhanvien.KiemTraDangNhap(nvdn) = True Then
                loai = nhanvien.loai
                Dim frm As New frmMain(Me.culInfoMgr)
                Me.Visible = False   ' ' ' ' ẩn form đăng nhập đi
                frm.ShowDialog()
            End If
            'loai = 


        Catch ex As Exception
            If cmbChangeLanguage.SelectedIndex = 0 Then
                MessageBox.Show("Kết Nối Thất Bại", "Lỗi Kết Nối", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show("Connect Database Faile", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If

        End Try

    End Sub



    Private Sub txtUserName_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUserName.KeyPress
        XuLiHam.NhapKiTu(sender, e)
    End Sub

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtUserName.Focus()
    End Sub

    Private Sub frmLogin_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        'If cmbChangeLanguage.SelectedIndex = 0 Then  '' ''' hiện form thoát khi chọn tiếng việt
        '    If thoat = 0 Then
        '        Dim str As DialogResult
        '        str = MessageBox.Show("Bạn muốn thoát chương trình?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
        '        If (str = DialogResult.No) Then
        '            e.Cancel = True
        '        End If
        '    End If
        'Else
        '    If thoat = 0 Then ' ' '''' hiện form thoát khi chọn tiếng anh
        '        Dim str As DialogResult
        '        str = MessageBox.Show("Are you Exit ?", "Exit programming", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
        '        If (str = DialogResult.No) Then
        '            e.Cancel = True
        '        End If
        '    End If
        'End If

    End Sub

End Class